from loguru import logger
from openpyxl import load_workbook


def read_excel(excel_file, sheet):
    """
    这是读取excel表格数据的一个方法
    :param excel_file: excel文件路径和名字
    :param sheet: 读取数据的表单
    :return: 读取后所有数据，保存为列表嵌套字典的格式，不包括第一行标题
    """
    wb = load_workbook(excel_file)
    sh = wb[sheet]
    cases = list(sh.values)
    list_case = []
    title_case = cases[0]
    for case in cases[1:]:
        data = dict(zip(title_case, case))
        list_case.append(data)
    logger.info(f"读取 {sheet} 页测试数据: {list_case}")
    return list_case


if __name__ == '__main__':
    from tools.handle_path import excel_path

    print(read_excel(excel_path, "登录"))
